package org.cuijq.thinking.in.spring.bean.definition;

import org.cuijq.thinking.in.spring.bean.factory.DefaultFactory;
import org.cuijq.thinking.in.spring.bean.factory.UserFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 初始化
 */
@Configuration
public class BeanInitializationDemo {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();

        ac.register(BeanInitializationDemo.class);

        ac.refresh();

        UserFactory userFactory = ac.getBean(UserFactory.class);
        System.out.println("准备关闭");
        ac.close();
        System.out.println("关闭");
    }

    @Bean(initMethod = "inituserFactory",destroyMethod = "doDestory")
    public UserFactory userFactory(){
        return new DefaultFactory();
    }


}
